Skip to main content
Version: 4.2

Overview

This document dedicates in demonstrating the process of obtaining data from supOS platform through common openAPIs.

info

Using open APIs to get data from supOS platform in external platforms requires authorization.

Operation Process

Getting Authorization

Get the AK/SK file from the supOS platform for subsequent use.

  1. Log in to supOS platform.
  2. In design center, select System Management > System Confirguation > AK/SK credential.
  3. Click New, enter the APP ID and then click OK.
  4. Click Donwload on the pop-up window to download the authorization file.
info

AK is the secret ID and SK is secret key in the file.

Calculating Signature

Use the following code to calculate the signature as authorization for using open API to get supOS platform data in third-party platforms.
Copy the following code in your IDE, change the AK/SK information to what you got from the supOS platform.

const crypto = require('crypto');
const ak="993034575ceaf0e166ad9a73fcf3c469"
const sk="62f6652846cf9096d680e7dc42f03ed1"
const supos="http://isv-integrate-pgx3.demo.devcloud.supos.net"
//sort query parameter
function sortQuery(jsonObj) {
if (jsonObj == null) return '';
let lowerCasekeyObj = {};
let lowerCasekeyArr = [];
for (const key in jsonObj) {
lowerKey = key.toLowerCase()
lowerCasekeyArr.push(lowerKey);
lowerCasekeyObj[lowerKey] = jsonObj[key];
}
let res = '';
lowerCasekeyArr.sort();
for (const i in lowerCasekeyArr) {
let key = lowerCasekeyArr[i];
res += lowerCasekeyArr[i] + "=" + lowerCasekeyObj[key] + "&";
}
return res.substring(0, res.length - 1);
}
//json convert query
function json2query(jsonObj) {
let res = '';
for (const key in jsonObj) {
res += key + "=" + jsonObj[key] + "&"
}
return res.substring(0, res.length - 1);
}
function buildSignString(uri, methodName, queryJson, headerJson) {
let signStr = ''
// HTTP Schema
signStr = signStr + methodName + "\n"
// HTTP URI
signStr = signStr + uri + "\n"
// HTTP ContentType
signStr = signStr + headerJson['Content-Type'] + "\n"
// CanonicalQueryString
signStr = signStr + sortQuery(queryJson) + "\n" + "\n"
return signStr
}
//AK/SK to get signature
function signHeader(uri, methodName, queryJson, headerJson) {
let signStr = buildSignString(uri, methodName, queryJson, headerJson);
console.log("signature source==========Start===========")
console.log(signStr)
console.log("signature source==========End===========")
let signature = crypto.createHmac('sha256', sk).update(signStr, 'utf8').digest('hex');
let final_signature = "Sign " + ak + "-" + signature
console.log("signature", final_signature)
headerJson['Authorization'] = final_signature;
}
module.exports = {
signHeader,
json2query,
supos
}

Calling API to get Data

In your IDE, create another file, and then copy the following code.

const hosted = require('./hosted.js')
const rp = require('request-promise');
function test() {
let openApiUri = '/open-api/organization/v2/companies';
methodName = 'GET' //DELETE/POST/PUT
let queryJson = {
"current": "1",
"pageSize": "500"
};
let headerJson = {
'Content-Type': 'application/json;charset=utf-8'
};
let wholeUrl=hosted.supos+openApiUri;
//queryJson contributes to the url but not the body
hosted.signHeader(openApiUri, methodName, queryJson, headerJson);
var options = {
method: methodName,
uri: wholeUrl,
headers: headerJson,
//body{}, enter body param of the API
json: true
};
if (queryJson != null) {
wholeUrl += "?" + hosted.json2query(queryJson);
options['uri'] = wholeUrl;
}
rp(options)
.then(function (response) {
console.log('response:', response);
})
.catch(function (err) {
console.error(err)
});

}
test()

Results

Run the calling API code to get the signature and results.
The signature should be like the following examples with different data obtained from supOS.

signature source==========Start===========
GET
/open-api/organization/v2/companies
application/json;charset=utf-8
current=1&pagesize=500


signature source==========End===========
signature: Sign 993034575ceaf0e166ad9a73fcf3c469-fb17c1b737f768a6153e2b69ce0f5c1df4f8bbcde5e3195c00fffb17e185822a